package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: HuoXu
 * @Date: 2023/08/26/11:37
 * @Description: 快乐跳跳虎
 */
@RestController
@Slf4j
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    public Result addCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("进入客户端添加购物车接口,{}", shoppingCartDTO);
        shoppingCartService.addCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车接口
     * @return
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> queryShoppingCart(){
        log.info("进入查看购物车的接口");
        List<ShoppingCart> list=shoppingCartService.queryShoppingCart();
        return Result.success(list);
    }

    /**
     *购物车中所选物品减一
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/sub")
    public Result shoppingCartSub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("进入购物车商品减少端口,{}",shoppingCartDTO);
        shoppingCartService.shoppingCartSub(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result shoppingCartClean(){
        shoppingCartService.shoppingCartClean();
        return Result.success();
    }
}
